﻿using Cemit.Awaiter;
using Cemit.NetFramework.Logger;
using Cemit.PolyProto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cemit.NetFramework
{
    /// <summary>与MainServer的相关操作</summary>
    class MainClient : PolyClient
    {
        /// <summary>获取大厅服务器列表</summary>
        public MonoAsyncAction<IEnumerable<LobbyInfo>> GetLobbyList()
        {
            var action  = new MonoAsyncAction<IEnumerable<LobbyInfo>>();

            if (!IsConnected)
            {
                throw action.ThrowException(new Exception("获取大厅列表失败：主服务器还未连接！"));
            }

            socket.Send(new Msg_Main_GetLobbyList())
                .AddCallback<Msg_Main_LobbyInfoList>(
                    msg => action.ReportResult(msg.ServerInfoList));

            return action;
        }
    }
}
